package sorter;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

import sorter.ISorter;

public class Bubblesort extends UnicastRemoteObject implements ISorter {

	protected Bubblesort() throws RemoteException {
		super();
	}

	public Comparable[] sort(Comparable[] comparable) {

		if (comparable == null)
			throw new IllegalArgumentException("De array is leeg.");
		else {
			boolean changed = false;
			do {
				changed = false;
				for (int a = 0; a < comparable.length - 1; a++) {
					if (comparable[a].compareTo(comparable[a + 1]) > 0) {
						Comparable tmp = comparable[a];
						comparable[a] = comparable[a + 1];
						comparable[a + 1] = tmp;
						changed = true;
					}
				}
			} while (changed);
		}
		return comparable;
	}

}
